﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace Tools.Utilities
{
    public class MailTools
    {
        //private MailAddress senderMailAddress;
        //private SmtpClient mailSenderClient;

        public MailTools()
        {
            //senderMailAddress = new MailAddress(CommonInfo.MailAddress().Decrypt());
            //CreateMailSenerClient();
        }

        private void CreateMailSenerClient()
        {
            //mailSenderClient = new SmtpClient(CommonInfo.SmtpHost().Decrypt(), 587);
            //mailSenderClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            //mailSenderClient.EnableSsl = true;
            //mailSenderClient.Credentials = new System.Net.NetworkCredential(CommonInfo.MailUser().Decrypt(), CommonInfo.MailPassword().Decrypt());
        }

        public bool SendEmail(string sentToAddress, string subject, string body)
        {
            bool result = false;
            int trycount = 0;
            while (!result && trycount < 5)
            {
                trycount++;
                try
                {
                    //MailMessage message = new MailMessage();

                    //message.From = senderMailAddress;
                    //message.To.Add(new MailAddress(sentToAddress));

                    //message.IsBodyHtml = true;
                    //message.BodyEncoding = Encoding.UTF8;
                    //message.Subject = subject;
                    //message.Body = body;

                    //mailSenderClient.Send(message);
                    //result = true;
                }
                catch
                {
                    result = false;
                }
            }
            return result;
        }
    }
}
